package com.version1_3.service.implement;

import com.alibaba.fastjson.JSONArray;
import com.google.gson.internal.LinkedTreeMap;
import com.util.format.MapToJson;
import com.version1_3.dao.ActivityDao;
import com.version1_3.dao.UserDao1_3;
import com.version1_3.service.ActivityService;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import com.util.property.Properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.sql.Date;
import java.text.DecimalFormat;
import java.util.*;

/**
 * Created by kuibu on 16/2/23.
 */
@Service
public class ActivityServiceImpl implements ActivityService {
    private static final Logger LOGGER = Logger.getLogger(ActivityServiceImpl.class);

    @Autowired
    private ActivityDao activityDao;

    @Autowired
    private UserDao1_3 userDao13;

    /**
     * 活动主页面信息
     */
    @Override
    public String activityMainPage(int userId) {

        List<Map<String, Object>> activityBannerList = activityDao.getActivityInfoByType(0);
        List<Map<String, Object>> activityList = activityDao.getActivityInfoByType(1);
        String userJoinedActivityInfo = userDao13.getUserJoinedActivityIds(userId);


        Map<String, Object> activityMainPageMap = new HashMap<>();
        activityMainPageMap.put("banner", activityBannerList); // 活动主页banner

        // 检测用户是否参与了活动
        for (Map activity : activityList) {

            if (userId != -1) {
                // 如果是跬步公益健身
                if ((long) activity.get("activityID") == Properties.KbActivity_jianshenID) {
                    if (userJoinedActivityInfo.contains(String.valueOf(Properties.KbActivity_fuwocheng)) || userJoinedActivityInfo.contains(String.valueOf(Properties.KbActivity_pingban)) || userJoinedActivityInfo.contains(String.valueOf(Properties.KbActivity_yangwo))) {
                        // 用户已经参加了跬步健身相关活动,需要发送用户坚持了多少天
                        activity.put("insistDays", activityDao.getInsistDays(userId, (int) Properties.KbActivity_jianshenID));
                        activity.put("hasJoined", true);
                    } else {
                        activity.put("hasJoined", false);
                    }
                } else if (userJoinedActivityInfo.contains(String.valueOf(activity.get("activityID")))) {
                    // 用户已经参加了跬步公益跑和骑行活动,需要发送用户坚持了多少天
                    activity.put("insistDays", activityDao.getInsistDays(userId, (int) ((long) activity.get("activityID"))));
                    activity.put("hasJoined", true);
                } else {
                    activity.put("hasJoined", false);
                }
            } else {
                // 未登陆用户
                activity.put("hasJoined", false);
            }
        }

        activityMainPageMap.put("activities", activityList); // 活动列表

        return JSONObject.fromObject(activityMainPageMap).toString();
    }

    /**
     * 活动详情页面
     */
    @Override
    public String activityInfo(int activityId) {

        Map activityInfo = activityDao.getActivityInfoById(activityId);

        if (activityInfo == null) {
            return "{\"code\":500}";
        } else {
            return JSONObject.fromObject(activityInfo).toString();
        }
    }

    /**
     * 参与活动
     */
    @Override
    public String joinActivity(int userId, int activityId) {
        String joinActivityResult = "{\"joinActivityResult\":" + activityDao.joinActivity(userId, activityId) + "}";
        return joinActivityResult;
    }

    /**
     * 活动打卡页面
     */
    @Override
    public String activityPage(int activityId, int userId) {
        // 发送数据Map
        Map<String, Object> activityPageMap = new HashMap<>();

        Map launchPageInfoMap = activityDao.getUserLaunchPageInfo(userId, activityId);

        /**
         * 用户一周的打卡情况
         */
        List<Map<String, Object>> weekLaunchInfo = activityDao.getUserWeekLaunchInfo(userId, activityId);
        int[] weekLaunchTag = new int[7];
        freshWeekLaunchTag(weekLaunchTag, weekLaunchInfo);


        /**
         * 公共数据设置
         */
        activityPageMap.put("days", launchPageInfoMap.get("days")); // 活动坚持天数
        activityPageMap.put("coin", launchPageInfoMap.get("coin")); // 活动积分
        activityPageMap.put("moneyCount", new DecimalFormat("#.00").format(activityDao.getUserDonateMoneyCount(userId))); // 所有活动捐献金额累积
        activityPageMap.put("money", launchPageInfoMap.get("money")); // 活动捐献金额
        activityPageMap.put("todayCount", 0); // 今日累积数据


        java.util.Date date = (java.util.Date) launchPageInfoMap.get("date");
        long time = Calendar.getInstance().getTime().getTime() - date.getTime();


        /**
         * 其他数据设置
         */
        if (time >= 0 && time <= 86400000) {
            /**
             * 今天已打卡
             */
            if (activityId == 11) {
                // 公益跑

                Map<String, Object> userBodyInfoMap = userDao13.getUserBodyInfo(userId); // 获取身高体重信息,用来计算跑路里程和卡路里

                // 利用公式计算跑步里程和卡路里
                double todayMile = ((BigDecimal) userBodyInfoMap.get("height")).intValue() * 0.0075 * ((BigDecimal) launchPageInfoMap.get("currData")).intValue();
                double mileCount = ((BigDecimal) userBodyInfoMap.get("height")).intValue() * 0.0075 * ((BigDecimal) launchPageInfoMap.get("currDataCount")).intValue();
                double calorie = ((BigDecimal) userBodyInfoMap.get("height")).intValue() * 0.75 / 100000 * ((BigDecimal) launchPageInfoMap.get("currDataCount")).intValue() * ((BigDecimal) userBodyInfoMap.get("height")).intValue() * 1.036;

                activityPageMap.put("money", new DecimalFormat("#.00").format(((BigDecimal) launchPageInfoMap.get("money")).doubleValue() + mileCount / 100000)); // 根据总跑步里程数计算捐献金额,里程数累计
                activityPageMap.put("mileCount", new DecimalFormat("#.000").format(mileCount / 1000)); // 跑步里程数 单位:公里
                activityPageMap.put("calorie", (int) calorie); // 消耗卡路里 单位:千
                activityPageMap.put("currStepNumber", launchPageInfoMap.get("currData")); // 今日步数
                activityPageMap.put("stepsCount", launchPageInfoMap.get("currDataCount")); // 跑步活动总步数

                //添加今日跑步里程数
                activityPageMap.put("todayCount", new DecimalFormat("#.000").format(todayMile / 1000));
            }

            if (activityId == 12) {
                // 骑行
                activityPageMap.put("currMileNumber", launchPageInfoMap.get("currData"));
                activityPageMap.put("mileCount", launchPageInfoMap.get("currDataCount"));
            }

            if (activityId == 13) {
                // 平板支撑
                activityPageMap.put("topRecord", (BigDecimal) launchPageInfoMap.get("maxCurrData")); // 发送时间为long类型的最高数据
                long data3 = (long) launchPageInfoMap.get("data3");
                activityPageMap.put("todayCount", data3 * 100); // 今日累积坚持秒数

                data3 = (data3 > 810) ? 810 : data3; // 每日捐献金额有限制
                activityPageMap.put("money", new DecimalFormat("#.00").format((data3 / 90) * 0.01)); // 捐赠金额根据用户总的平板支撑时间来计算,90秒捐赠0.01元
            }

            if (activityId == 14 || activityId == 15) {
                // 仰卧起坐 | 俯卧撑

                // 仰卧起坐和俯卧撑如果不打满4组,不算做一次打卡
                if (((BigDecimal) launchPageInfoMap.get("currData")).intValue() != 4) {
                    weekLaunchTag[(((GregorianCalendar) Calendar.getInstance()).get(Calendar.DAY_OF_WEEK) + 5) % 7] = 0;
                }


                activityPageMap.put("progress", ((BigDecimal) launchPageInfoMap.get("currData")));
                activityPageMap.put("numPerGroup", Integer.parseInt((String) launchPageInfoMap.get("data1")));

                long data3 = (long) launchPageInfoMap.get("data3");
                activityPageMap.put("todayCount", data3); // 今日累积坚持个数

                data3 = (data3 > 720) ? 720 : data3; // 每日捐献金额有限制
                activityPageMap.put("money", new DecimalFormat("#.00").format((data3 / 80) * 0.01)); // 捐赠金额根据用户总的平板支撑时间来计算,80个0.01元
            }

        } else {
            /**
             * 今天未打卡
             */
            if (activityId == 11) {
                // 公益跑
                activityPageMap.put("currStepNumber", 0);

                // 获取身高体重信息,用来计算跑路里程和卡路里
                Map<String, Object> userBodyInfoMap = userDao13.getUserBodyInfo(userId);

                // 利用公式计算跑步里程和卡路里
                try {
                    double mileCount = ((BigDecimal) userBodyInfoMap.get("height")).intValue() * 0.0075 * ((BigDecimal) launchPageInfoMap.get("currDataCount")).intValue();
                    double calorie = ((BigDecimal) userBodyInfoMap.get("height")).intValue() * 0.75 / 100000 * ((BigDecimal) launchPageInfoMap.get("currDataCount")).intValue() * ((BigDecimal) userBodyInfoMap.get("height")).intValue() * 1.036;

                    activityPageMap.put("mileCount", new DecimalFormat("#.000").format(mileCount / 1000)); // 跑步里程数 单位:公里
                    activityPageMap.put("calorie", (int) calorie); // 消耗卡路里 单位:千卡

                } catch (Exception excepiton) {
                    // 解决没有打卡记录导致错误
                    double mileCount = ((BigDecimal) userBodyInfoMap.get("height")).intValue() * 0.0075 * (int) launchPageInfoMap.get("currDataCount");
                    double calorie = ((BigDecimal) userBodyInfoMap.get("height")).intValue() * 0.75 / 100000 * (int) launchPageInfoMap.get("currDataCount") * ((BigDecimal) userBodyInfoMap.get("height")).intValue() * 1.036;

                    activityPageMap.put("mileCount", new DecimalFormat("#.000").format(mileCount / 1000)); // 跑步里程数 单位:公里,觉得这里计算有问题
                    activityPageMap.put("calorie", (int) calorie); // 消耗卡路里 单位:千卡
                }

                activityPageMap.put("stepsCount", launchPageInfoMap.get("currDataCount"));
            }

            if (activityId == 12) {
                // 骑行
                activityPageMap.put("currMileNumber", 0);
                activityPageMap.put("mileCount", launchPageInfoMap.get("currDataCount"));
            }

            if (activityId == 13) {
                // 平板支撑
                activityPageMap.put("topRecord", launchPageInfoMap.get("maxCurrData")); // 发送时间为long类型的最高数据
            }

            if (activityId == 14 || activityId == 15) {
                // 仰卧起坐 | 俯卧撑
                activityPageMap.put("numPerGroup", 20); // 默认20组
                activityPageMap.put("progress", 0); // 默认进度为0
            }
        }

        // 一周打卡情况
        activityPageMap.put("today", ((GregorianCalendar) Calendar.getInstance()).get(Calendar.DAY_OF_WEEK));
        activityPageMap.put("MON", weekLaunchTag[0]);
        activityPageMap.put("TUE", weekLaunchTag[1]);
        activityPageMap.put("WED", weekLaunchTag[2]);
        activityPageMap.put("THU", weekLaunchTag[3]);
        activityPageMap.put("FRI", weekLaunchTag[4]);
        activityPageMap.put("SAT", weekLaunchTag[5]);
        activityPageMap.put("SUN", weekLaunchTag[6]);

        return JSONObject.fromObject(activityPageMap).toString();
    }

    /**
     * 打卡
     */
    @Override
    public String launchActivity(int activityId, int userId, Object data) {

        Map launchPageInfoMap = activityDao.getUserLaunchPageInfo(userId, activityId);

        java.util.Date date = (java.util.Date) launchPageInfoMap.get("date");
        long time = Calendar.getInstance().getTime().getTime() - date.getTime();
        boolean hasLaunched = false;
        boolean launchResult = true;

        if (time >= 0 && time <= 86400000) {
            hasLaunched = true;
        }


        if (activityId == 11) {
            // 公益跑

            int currData = (int) ((double) data);
            if (!hasLaunched) {
                // 今天未打卡

                // 获取身高体重信息,用来计算跑路里程和卡路里
                Map<String, Object> userBodyInfoMap = userDao13.getUserBodyInfo(userId);
                int coin = (int) (((BigDecimal) userBodyInfoMap.get("height")).intValue() * 0.0075 * currData) / 1000; // 计算积分
                if (coin > 50) {
                    coin = 50;
                }

                double money = 0.05; // 计算捐献公益基金钱数 + 当日首次打卡赠送0.05元

                activityDao.addNewLaunchRecord(userId, activityId, String.valueOf(currData), "", 0, coin, money);
                activityDao.addUserActivityCoin(userId, activityId, 10); // 用户当日首次打卡增加10积分
            } else {
                // 今天已打卡
                int currDataNew = currData + ((BigDecimal) launchPageInfoMap.get("currData")).intValue();

                // 获取身高体重信息,用来计算跑路里程和卡路里
                Map<String, Object> userBodyInfoMap = userDao13.getUserBodyInfo(userId);
                int addCoin = (int) (((BigDecimal) userBodyInfoMap.get("height")).intValue() * 0.0075 * currDataNew) / 1000;
                int coinNew = ((BigDecimal) launchPageInfoMap.get("coin")).intValue() + addCoin;

                if (coinNew > 50) { // 计算新的积分
                    coinNew = 50;
                }

                activityDao.addLaunchRecord(userId, activityId, String.valueOf(currDataNew), "", coinNew, 0.05);
            }

        }

        if (activityId == 12) {
            // 骑行
            double currData = (double) data;
            if (!hasLaunched) {
                // 今天未打卡
                activityDao.addNewLaunchRecord(userId, activityId, String.valueOf(currData), "", 0, 0, 0);
                activityDao.addUserActivityCoin(userId, activityId, 10); // 用户当日首次打卡增加10积分
            } else {
                // 今天已打卡
                double currDataNew = currData + ((BigDecimal) launchPageInfoMap.get("currData")).doubleValue();
                activityDao.addLaunchRecord(userId, activityId, String.valueOf(currDataNew), "", 10, 0);
            }
        }

        if (activityId == 13) {
            // 平板支撑
            long currData = (long) ((double) data);

            if (!hasLaunched) {
                // 今天未打卡
                double money = 0.01; // 当日首次打卡赠送0.01元

                activityDao.addNewLaunchRecord(userId, activityId, String.valueOf(currData), "", (int) currData / 100, 0, money);
                activityDao.addUserActivityCoin(userId, activityId, 10); // 用户当日首次打卡增加10积分
            } else {
                // 今天已打卡
                long currDataNew = currData;
                // int data3 = (int) launchPageInfoMap.get("data3");

                /*// 平板支撑每天最多捐献0.1元,每90秒0.01元,初始打卡0.01元,至多有效个数是810个
                if ((data3 + currDataNew / 100) > 810) {
                    currData = 81000 - data3 * 100;
                }*/

                activityDao.freshLaunchRecord(userId, activityId, String.valueOf(currDataNew), (int) currData / 100, 10, 0.01);
            }
        }

        if (activityId == 14 || activityId == 15) {
            // 仰卧起坐 | 俯卧撑
            try {
                // 安卓端使用的是组数数据,progress服务器来管理
                int currData = (int) ((double) data);
                if (!hasLaunched) {
                    // 今天未打卡
                    double money = 0.01;
                    activityDao.addNewLaunchRecord(userId, activityId, String.valueOf(1), String.valueOf(currData), currData, 0, money);
                    activityDao.addUserActivityCoin(userId, activityId, 10); // 用户当日首次打卡增加10积分
                } else {
                    // 今天已打卡
                    Map<String, Object> userTodayActivityInfo = activityDao.getUserTodayActivityInfo(userId, activityId);

                    if (userTodayActivityInfo != null) {
                        int progress = ((BigDecimal) userTodayActivityInfo.get("currData")).intValue();

                        // 一天打卡多次时初始化进度
                        if (progress + 1 > 4) {
                            progress = 0;
                        }

                        // int data3 = (int) launchPageInfoMap.get("data3");

                        // 仰卧起坐和俯卧撑每天最多捐献0.1元,初始打卡0.01元,80个0.01元,最多有效个数是720个
                        /*if ((data3 + currData) > 720) {
                            currData = 720 - data3;
                        }*/

                        activityDao.freshLaunchRecord(userId, activityId, String.valueOf(progress + 1), currData, 10, 0.01);
                    }

                }
            } catch (Exception exception) {
                // iOS端使用的是每组个数和进度作为data
                JSONObject jsonObject = JSONObject.fromObject((LinkedTreeMap) data);
                int numPerGroup = jsonObject.getInt("numPerGroup");
                int progress = jsonObject.getInt("progress");

                // 每天重复打卡时,初始化进度
                if (progress > 4) {
                    progress = 0;
                }

                if (!hasLaunched) {
                    // 今天未打卡
                    double money = numPerGroup / 80 * 0.01;
                    activityDao.addNewLaunchRecord(userId, activityId, String.valueOf(progress), String.valueOf(numPerGroup), numPerGroup, 0, money);
                    activityDao.addUserActivityCoin(userId, activityId, 10); // 用户当日首次打卡增加10积分
                } else {
                    // 今天已打卡
                    /*int data3 = (int) launchPageInfoMap.get("data3");
                    if ((data3 + numPerGroup) > 720) {
                        numPerGroup = 720 - data3;
                    }*/

                    activityDao.freshLaunchRecord(userId, activityId, String.valueOf(progress), numPerGroup, 10, 0.01);
                }
            }


        }


        String activityPageInfo = activityPage(activityId, userId);
        JSONObject activityNewPageInfo = JSONObject.fromObject(activityPageInfo);
        activityNewPageInfo.put("launchResult", launchResult);

        return activityNewPageInfo.toString();
    }

    /**
     * 我的活动
     */
    @Override
    public String myActivity(int userId) {

        List<Map<String, Object>> userActivityInList = activityDao.getUserActivityInfo(userId);

        Map<String, Object> activityInfo = new HashMap<>();

        String userJoinedAcitivityIds = userDao13.getUserJoinedActivityIds(userId);
        JSONArray jsonArray = JSONArray.parseArray(userJoinedAcitivityIds);
        List userHasLaunchedActivities = new ArrayList<>();

        List<Map<String, Object>> activityList = new ArrayList<>();
        double moneyCount = 0;
        int coin = 0;

        // 参加并打过卡
        for (Map activityMap : userActivityInList) {
            moneyCount = moneyCount + ((BigDecimal) activityMap.get("money")).doubleValue();
            coin = coin + ((BigDecimal) activityMap.get("coin")).intValue();

            Map<String, Object> activity = new HashMap<>();

            activity.put("activityId", activityMap.get("activityID"));
            activity.put("activityName", activityMap.get("activityTitle"));
            activity.put("insistDays", activityMap.get("days"));

            Date date = (Date) activityMap.get("date");

            long time = Calendar.getInstance().getTime().getTime() - date.getTime();
            if (time >= 0 && time <= 86400000) {
                activity.put("hasLaunched", true);
            } else {
                activity.put("hasLaunched", false);
            }

            activityList.add(activity);
            userHasLaunchedActivities.add(activityMap.get("activityID"));
        }

        // 已参加,但未打卡
        for (int i = 0; i < jsonArray.size(); i++) {
            if (!userHasLaunchedActivities.contains(jsonArray.get(i))) {
                Map<String, Object> activityInfoMap = activityDao.getActivityInfoById(jsonArray.getIntValue(i));
                Map<String, Object> activity = new HashMap<>();

                activity.put("activityId", jsonArray.getIntValue(i));
                activity.put("activityName", activityInfoMap.get("activityTitle"));
                activity.put("insistDays", 0);
                activity.put("hasLaunched", false);
                activityList.add(activity); // 未打过卡,已参与活动的数据
            }
        }

        activityInfo.put("moneyCount", activityDao.getUserDonateMoneyCount(userId));
        activityInfo.put("coin", coin);
        activityInfo.put("activities", activityList);


        return JSONObject.fromObject(activityInfo).toString();
    }

    /**
     * 填写身高体重信息
     *
     * @param userId
     * @param height
     * @param weight
     */
    @Override
    public String setBodyInfo(int userId, double height, double weight, String name, String school) {

        boolean setBodyInfoResult = userDao13.setBodyInfo(userId, height, weight, name, school);
        return new MapToJson("setBodyInfoResult", setBodyInfoResult).toJsonString();
    }


    /**
     * 获取用户活动捐献钱数
     *
     * @param userId
     * @param activityId
     * @return
     */
    @Override
    public Map<String, Object> getShareLaunchCardInfo(int userId, int activityId) {
        return activityDao.getShareLaunchCardInfo(userId, activityId);
    }

    @Override
    public boolean recordActivityShare(int userId, int activityId) {

        return activityDao.recordActivityShare(userId, activityId);
    }

    /**
     * 根据用户打卡数据判断用户一周打卡情况
     *
     * @param weekLaunchTag
     * @param weekLaunchInfo
     * @return
     */
    public boolean freshWeekLaunchTag(int[] weekLaunchTag, List<Map<String, Object>> weekLaunchInfo) {
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
        gc.get(Calendar.DAY_OF_WEEK);

        Calendar calendar = Calendar.getInstance();

        // 初始化标志数组
        for (int i : weekLaunchTag) {
            weekLaunchTag[i] = 0;
        }

        switch (gc.get(Calendar.DAY_OF_WEEK)) {
            // 星期天
            case 1:
                for (int i = 0; i < 7; i++) {
                    try {
                        Date date = (Date) weekLaunchInfo.get(i).get("date");
                        long time = calendar.getTime().getTime() - date.getTime();

                        int temp = (int) (time / 86400000);
                        weekLaunchTag[6 - temp] = 1;
                    } catch (IndexOutOfBoundsException exception) {
                        LOGGER.info("没有足够的一周数据,weekLaunchInfoNumber: " + weekLaunchInfo.size());
                    }
                }

                break;
            // 星期一
            case 2:
                try {
                    Date date1 = (Date) weekLaunchInfo.get(0).get("date");
                    calendar.add(Calendar.DATE, 0);
                    long time1 = calendar.getTime().getTime() - date1.getTime();

                    if (time1 >= 0 && time1 <= 86400000) {
                        weekLaunchTag[0] = 1;
                    } else {
                        weekLaunchTag[0] = 0;
                    }
                } catch (IndexOutOfBoundsException exception) {
                    LOGGER.info("没有足够的一周数据,weekLaunchInfoNumber: " + weekLaunchInfo.size());
                }
                break;
            // 星期二
            case 3:
                for (int i = 0; i < 2; i++) {
                    try {
                        Date date = (Date) weekLaunchInfo.get(i).get("date");
                        long time = calendar.getTime().getTime() - date.getTime();

                        int temp = (int) (time / 86400000);
                        weekLaunchTag[1 - temp] = 1;
                    } catch (IndexOutOfBoundsException exception) {
                        LOGGER.info("没有足够的一周数据,weekLaunchInfoNumber: " + weekLaunchInfo.size());
                    }
                }
                break;
            // 星期三
            case 4:
                for (int i = 0; i < 3; i++) {

                    try {
                        Date date = (Date) weekLaunchInfo.get(i).get("date");
                        long time = calendar.getTime().getTime() - date.getTime();

                        int temp = (int) (time / 86400000);
                        weekLaunchTag[2 - temp] = 1;
                    } catch (IndexOutOfBoundsException exception) {
                        LOGGER.info("没有足够的一周数据,weekLaunchInfoNumber: " + weekLaunchInfo.size());
                    }
                }
                break;
            // 星期四
            case 5:
                for (int i = 0; i < 4; i++) {

                    try {
                        Date date = (Date) weekLaunchInfo.get(i).get("date");
                        long time = calendar.getTime().getTime() - date.getTime();

                        int temp = (int) (time / 86400000);
                        weekLaunchTag[3 - temp] = 1;
                    } catch (IndexOutOfBoundsException exception) {
                        LOGGER.info("没有足够的一周数据,weekLaunchInfoNumber: " + weekLaunchInfo.size());
                    }
                }
                break;
            // 星期五
            case 6:
                for (int i = 0; i < 5; i++) {

                    try {
                        Date date = (Date) weekLaunchInfo.get(i).get("date");
                        long time = calendar.getTime().getTime() - date.getTime();

                        int temp = (int) (time / 86400000);
                        weekLaunchTag[4 - temp] = 1;
                    } catch (IndexOutOfBoundsException exception) {
                        LOGGER.info("没有足够的一周数据,weekLaunchInfoNumber: " + weekLaunchInfo.size());
                    }
                }
                break;
            // 星期六
            case 7:
                for (int i = 0; i < 6; i++) {

                    try {
                        Date date = (Date) weekLaunchInfo.get(i).get("date");
                        long time = calendar.getTime().getTime() - date.getTime();

                        int temp = (int) (time / 86400000);
                        weekLaunchTag[5 - temp] = 1;

                        // 为了测试打卡日期错误情况,作出的LOGGER测试
                        //LOGGER.error("第" + (i + 1) + "个数据: 从数据库取出的日期是 " + date.toString() + "\ntime: " + time + "\ntime/86400000= " + temp);

                    } catch (Exception excetpion) {
                        LOGGER.info("没有足够的一周数据,weekLaunchInfoNumber: " + weekLaunchInfo.size());
                    }
                }
                break;
        }

        return true;
    }

    public static void main(String[] args) {
        /*Map<String, Object> testMap = new HashMap<>();
        testMap.put("money", 0);
        testMap.put("money", 2);
        System.out.println(testMap.toString());*/
    }
}
